<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

function smarty_function_sitebar_news($params,$smarty){
	$smarty->CI->load->model('news_model');
	$categories = array();
	$categories = $smarty->CI->news_model->get_categories(array('parent_id'=>0));
	$html = "";
	$news = array();
	foreach ($categories as $category){
		
		$news = $smarty->CI->news_model->get_news(array('category_id'=>$category['category_id'],'limit'=>5));
		$html .= "<div class=\"sitebar\">"."\n"
			  ."<div class=\"sitebar-title\"><h3>{$category[name]}</h3></div>"."\n";
		
		$html .= "<div class=\"sitebar-content\">"
			  ."<ul class=\"nlist\">";
		if (is_array($news)){
			foreach ($news as $new){
				$html .= "<li class=\"nitem\">"
					."<a href=\"{$new[link]}\" title=\"{$new[name]}\">{$new[name]}</a>"
					."</li>"."\n";
			}
		}
		$html .="</ul>";
		$html .="</div>"."\n";
		$html .="</div>"."\n";
	}
	return $html;
}